package com.ok.es.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {
    //声明漫画Fanout交换机
    @Bean
    public FanoutExchange fanoutExchange(){
//        return ExchangeBuilder.fanoutExchange("hmall.fanout").build();
        return new FanoutExchange("cartoon_direct");
    }

    //声明第一个队列
    @Bean
    public Queue fanoutQueue1(){
//        return QueueBuilder.durable("fanout.queue1").build();
        return new Queue("cartoon_add_queue");
    }

    //绑定队列1和交换机
    @Bean
    public Binding bindingQueue1(Queue fanoutQueue1,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    //声明第二个队列
    @Bean
    public Queue fanoutQueue2(){
//        return QueueBuilder.durable("fanout.queue2").build();
        return new Queue("cartoon_rm_queue");
    }

    //绑定队列2和交换机
    @Bean
    public Binding bindingQueue2(Queue fanoutQueue2,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    //声明第三个队列
    @Bean
    public Queue fanoutQueue3(){
        return new Queue("cartoon_update_queue");
    }

    //绑定队列2和交换机
    @Bean
    public Binding bindingQueue3(Queue fanoutQueue3,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue3).to(fanoutExchange);
    }

    //////////////////////////////////////////////////

    //声明帖子Fanout交换机
    @Bean
    public FanoutExchange CardExchange(){
        return new FanoutExchange("card_direct");
    }

    //声明第一个队列
    @Bean
    public Queue CardQueue1(){
        return new Queue("card_add_queue");
    }

    //绑定队列1和交换机
    @Bean
    public Binding bindingQueue4(Queue CardQueue1,FanoutExchange CardExchange){
        return BindingBuilder.bind(CardQueue1).to(CardExchange);
    }

    //声明第二个队列
    @Bean
    public Queue CardQueue2(){
        return new Queue("card_rm_queue");
    }

    //绑定队列2和交换机
    @Bean
    public Binding bindingQueue5(Queue CardQueue2,FanoutExchange CardExchange){
        return BindingBuilder.bind(CardQueue2).to(CardExchange);
    }

    //声明第三个队列
    @Bean
    public Queue CardQueue3(){
        return new Queue("card_update_queue");
    }

    //绑定队列2和交换机
    @Bean
    public Binding bindingQueue6(Queue CardQueue3,FanoutExchange CardExchange){
        return BindingBuilder.bind(CardQueue3).to(CardExchange);
    }
}
